package online.longzipeng;

/**
 * @Author: lzp
 * @description:
 * @Date: 2023/10/12
 */
public class ListNode {
	int val;
	ListNode next;

	ListNode() {
	}

	ListNode(int val) {
		this.val = val;
	}

	/**
	 * 初始化N个节点的链表
	 */
	ListNode(int... vals) {
		this.val = vals[0];
		if (vals.length > 1) {
			ListNode cur = this;
			// 遍历生成下一个节点
			for (int i = 1; i < vals.length; i++) {
				cur.next = new ListNode(vals[i]);
				cur = cur.next;
			}
		}
	}

	ListNode(int val, ListNode next) {
		this.val = val;
		this.next = next;
	}
}